package presentacion.tags;

import integracion.DatabaseManager;
import integracion.ComponenteDAO;

import java.io.IOException;
import java.sql.SQLException;
import java.util.ArrayList;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.TagSupport;

import share.Componente;

public class ObtenerComponentes extends TagSupport
{

	/**
	 *
	 */
	private static final long serialVersionUID = 1L;
	private String name;


	public int doStartTag() throws JspException
	{
		JspWriter out = pageContext.getOut();

		try
		{
			out.println("<select name=\""+name+"\">");

			ComponenteDAO dao = new ComponenteDAO(DatabaseManager.getConnection());
			ArrayList<Componente> lista = dao.getLista();

			for (Componente d : lista)
			{
				out.println("<option value=\""+d.getId()+"\">");
				out.print(d.getNombre()+"</option>");
			}

			out.println("</select>");
		}
		catch (IOException e)
		{
			e.printStackTrace();
		} catch (SQLException e) {
			e.printStackTrace();
		}

		return 0;
	}

	public String getName()
	{
		return name;
	}

	public void setName(String name)
	{
		this.name = name;
	}
}
